﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;

namespace PearTunes.WEB.Helpers
{
    /// <summary>
    /// Attribute to mark many-to-many connection to be serialized only by certain depth
    /// </summary>
    public class ReferencePreservingDataContractFormatAttribute : Attribute, IOperationBehavior
    {
        #region IOperationBehavior Members
        /// <summary>
        /// Adds binding parameters
        /// </summary>
        /// <param name="description">Description of the operation</param>
        /// <param name="parameters">Binding parameter collection</param>
        public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
        {
        }
        /// <summary>
        /// Applies the certain client behavior
        /// </summary>
        /// <param name="description">Description of the operation</param>
        /// <param name="proxy">Proxy for the client operations</param>
        public void ApplyClientBehavior(OperationDescription description, System.ServiceModel.Dispatcher.ClientOperation proxy)
        {
            IOperationBehavior innerBehavior = new ReferencePreservingDataContractSerializerOperationBehavior(description);
            innerBehavior.ApplyClientBehavior(description, proxy);
        }
        /// <summary>
        /// Applies the certain dispatch behavior
        /// </summary>
        /// <param name="description">Description of the operation</param>
        /// <param name="dispatch">Proxy for the dispatcher operations</param>
        public void ApplyDispatchBehavior(OperationDescription description, System.ServiceModel.Dispatcher.DispatchOperation dispatch)
        {
            IOperationBehavior innerBehavior = new ReferencePreservingDataContractSerializerOperationBehavior(description);
            innerBehavior.ApplyDispatchBehavior(description, dispatch);
        }
        /// <summary>
        /// Validates the object
        /// </summary>
        /// <param name="description">Description of the operation</param>
        public void Validate(OperationDescription description)
        {
        }

        #endregion
    }
}